package com.example.wechat.activity;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.wechat.R;
import com.example.wechat.adapter.PhotoAdapter;
import java.util.ArrayList;
import java.util.List;

public class AlbumActivity extends AppCompatActivity implements PhotoAdapter.OnPhotoClickListener {
    private RecyclerView photoGrid;
    private PhotoAdapter photoAdapter;
    private List<Integer> photoList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_album);

        // 设置工具栏
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowTitleEnabled(true);
        }

        // 初始化相册列表
        photoGrid = findViewById(R.id.photo_grid);
        photoGrid.setLayoutManager(new GridLayoutManager(this, 3));
        
        // 添加示例图片
        photoList = new ArrayList<>();
        photoList.add(R.drawable.photo_1);
        photoList.add(R.drawable.photo_2);
        photoList.add(R.drawable.photo_3);
        photoList.add(R.drawable.photo_4);
        photoList.add(R.drawable.photo_5);
        photoList.add(R.drawable.photo_6);

        photoAdapter = new PhotoAdapter(this, photoList, this);
        photoGrid.setAdapter(photoAdapter);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onPhotoClick(int position) {
        Toast.makeText(this, "查看图片 " + (position + 1), Toast.LENGTH_SHORT).show();
        // TODO: 实现图片查看功能
    }
} 